package com.fz.interceptor;

import com.sun.deploy.net.HttpResponse;
import org.apache.ibatis.session.SqlSession;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by webrx on 2017/6/29.
 */

public class TestInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object o) throws Exception {
        //return false;
        HttpSession  session =req.getSession();
        String user=null;
        try{

            user= session.getAttribute("member").toString();

        }catch (Exception e){

        }
        HttpServletResponse response =resp;
        HttpServletRequest request=req;
        System.out.println(user+"***********");
        if(user==null){
            String c =req.getContextPath();
            response.sendRedirect(c+"/long.jsp");

        }
        System.out.println(user);
        return true;
    }

    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("拦截器——处理后");
    }

    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("拦截器最后执行");
    }
}
